using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Data;
using QLNS.Object;

namespace QLNS
{
    public class staticClass
    {
        static public bool searched = false;
        static public bool calculated = false;
        static public long MucNangDong = 200000;
        static public float phantramCap1 = 0.1f;
        static public float phantramCap2 = 0.05f;
        static public NguoiDung_obj NguoiDungStatic;
        static public bool reLogin = false;
        public staticClass() { }
        public static long LuongCoBan = 540000;
        //Tat ca cot deu not null
        public static bool KiemTraThemDong(DataGridView dg)
        {
            try
            {
                for (int i = 0; i <= dg.Columns.Count - 1; i++)
                    if (Convert.ToString(dg.Rows[dg.Rows.Count - 1].Cells[i].Value) == "")
                        return false;
            }
            catch{}
            return true;
        }
        //Co cot null
        public static bool KiemTraThemDong(DataGridView dg,params int[] a)
        {
            try
            {
                for (int i = 0; i <= a.Length - 1; i++)
                    if (Convert.ToString(dg.Rows[dg.Rows.Count - 1].Cells[a[i]].Value) == "")
                        return false;
            }
            catch { }
            return true;
        }
        //Truong hop chi co 1 cot lam khoa chinh
        public static bool KiemTraKhoaChinh(DataGridView dg, int khoa1)
        { 
            int tontai =0;
            try
            {
                for (int i = 0; i <= dg.Rows.Count - 1; i++)
                    if (dg.Rows[i].Cells[khoa1].Value.ToString().Trim() == dg.Rows[dg.Rows.Count - 1].Cells[khoa1].Value.ToString().Trim())
                        tontai++;
            }
            catch { }
            if (tontai <= 1)
                return true;
            return false;
        }
        //Truong hop co 2 cot lam khoa chinh
        public static bool KiemTraKhoaChinh(DataGridView dg, int khoa1, int khoa2)
        {
            int tontai = 0;
            try
            {
                for (int i = 0; i <= dg.Rows.Count - 1; i++)
                    if (dg.Rows[i].Cells[khoa1].Value.ToString().Trim() == dg.Rows[dg.Rows.Count - 1].Cells[khoa1].Value.ToString().Trim())
                        if (dg.Rows[i].Cells[khoa2].Value.ToString().Trim() == dg.Rows[dg.Rows.Count - 1].Cells[khoa2].Value.ToString().Trim())
                            tontai++;
            }
            catch { }
            if (tontai <= 1)
                return true;
            return false;
        }
        //Truong hop co 3 cot lam khoa chinh
        public static bool KiemTraKhoaChinh(DataGridView dg, int khoa1, int khoa2, int khoa3)
        {
            int tontai = 0;
            try
            {
                for (int i = 0; i <= dg.Rows.Count - 1; i++)
                    if (dg.Rows[i].Cells[khoa1].Value.ToString().Trim() == dg.Rows[dg.Rows.Count - 1].Cells[khoa1].Value.ToString().Trim())
                        if (dg.Rows[i].Cells[khoa2].Value.ToString().Trim() == dg.Rows[dg.Rows.Count - 1].Cells[khoa2].Value.ToString().Trim())
                            if (dg.Rows[i].Cells[khoa3].Value.ToString().Trim() == dg.Rows[dg.Rows.Count - 1].Cells[khoa3].Value.ToString().Trim())
                                tontai++;
            }
            catch { }
            if (tontai <= 1)
                return true;
            return false;
        }

        ////Kiem tra khoa ngoai
        public static bool KiemTraKhoaNgoai(DataTable tbl, string tenkhoa, string khoa)
        {
            foreach (DataRow row in tbl.Rows)
                if (row[tenkhoa].ToString().Trim() == khoa.Trim())
                    return true;
            return false;
        }
    }
}
